"""
迭代器：实现了迭代协议的对象。
    ~ 魔术方法：__xxx__
    ~ __next__ / __iter__
上下文管理器：实现了上下文管理器协议的对象
    ~ __enter__ / __exit__
"""
# 1 1 2 3 5 8 13 21 34 55


class FibIter:

    def __init__(self, num):
        self.num = num
        self.a, self.b = 0, 1
        self.count = 0

    def __iter__(self):
        return self

    def __next__(self):
        if self.count < self.num:
            self.a, self.b = self.b, self.a + self.b
            self.count += 1
            return self.a
        raise StopIteration()


for value in FibIter(20):
    print(value)

print(4181 / 6765)
